//
//  TechDetailViewCell.m
//  LPSNews
//
//  Created by Ruan on 14-10-18.
//  Copyright (c) 2014年 LPS. All rights reserved.
//

#import "TechDetailViewCell.h"

@implementation TechDetailViewCell


-(void)dealloc
{
    [_techDetailTitle release];
    [_ptimeLabel release];
    [_techDetailContent release];
    [_techDetailContentLabel release];
    [_indexPath release];
    [_techDetailData release];
    [super dealloc];
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        
        UILabel *techDetailTitle = [[UILabel alloc] init];
        UILabel *ptimeLabel = [[UILabel alloc] init];
        UIWebView *techDetailContent = [[UIWebView alloc] init];
        
        UILabel *techDetailContentLabel = [[UILabel alloc] init];
        
        self.techDetailTitle = techDetailTitle;
        self.ptimeLabel = ptimeLabel;
        self.techDetailContent = techDetailContent;
        self.techDetailContentLabel = techDetailContentLabel;
        
        
        [self.contentView addSubview:techDetailTitle];
        [self.contentView addSubview:ptimeLabel];
        [self.contentView addSubview:techDetailContent];
        [self.contentView addSubview:techDetailContentLabel];
        
        [techDetailTitle release];
        [ptimeLabel release];
        [techDetailContent release];
        [techDetailContentLabel release];
    }
    return self;
}


- (void)setTechDetailData:(TechDetailMode *)techDetailData
{
    _techDetailData = techDetailData;
    
   
    self.techDetailTitle.text = _techDetailData.title;
    self.techDetailTitle.font = [UIFont systemFontOfSize:17];
    self.techDetailTitle.textAlignment = NSTextAlignmentCenter;
    self.techDetailTitle.lineBreakMode = NSLineBreakByCharWrapping;
    self.techDetailTitle.numberOfLines = 0;
    CGRect techDetailTitleFrame = [self.techDetailTitle.text boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width - 10, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20]} context:nil];
     self.techDetailTitle.frame = CGRectMake(5, 10, [UIScreen mainScreen].bounds.size.width - 10, CGRectGetHeight(techDetailTitleFrame));
    
    self.ptimeLabel.frame = CGRectMake(5, CGRectGetMaxY(self.techDetailTitle.frame), [UIScreen mainScreen].bounds.size.width , 10);
    self.ptimeLabel.text = _techDetailData.ptime;
    self.ptimeLabel.textAlignment = NSTextAlignmentCenter;
    self.ptimeLabel.font = [UIFont systemFontOfSize:8];
    self.ptimeLabel.textColor = [UIColor grayColor];

    self.techDetailContentLabel.frame = CGRectMake(5, CGRectGetMaxY(self.ptimeLabel.frame), [UIScreen mainScreen].bounds.size.width-5 , 1000);
    
//    [self.techDetailContentLabel setContentToHTMLString:_techDetailData.body];
//    UITextView
    
    
    self.techDetailContent.frame =  CGRectMake(5, CGRectGetMaxY(self.ptimeLabel.frame), [UIScreen mainScreen].bounds.size.width-5 , 1000);
    
        [self.techDetailContent loadHTMLString:_techDetailData.body baseURL:nil];

    self.techDetailContent.scrollView.scrollEnabled = NO;
    self.techDetailContent.delegate = self;
    
}




- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//    [self.techDetailContent stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust='85%'"];
//    
//    NSString *height_str= [self.techDetailContent stringByEvaluatingJavaScriptFromString: @"document.body.offsetHeight"];
//    CGFloat height = [height_str floatValue];
//    
//    self.techDetailContent.frame =  CGRectMake(5, CGRectGetMaxY(self.ptimeLabel.frame), [UIScreen mainScreen].bounds.size.width-5, height+10);
//   
//    if (_delegate && [_delegate respondsToSelector:@selector(updataTableViewRowHeight:cellForRowAtIndexPath:)] ) {
//       [_delegate updataTableViewRowHeight:height + 100  cellForRowAtIndexPath:self.indexPath];
//    }
    
    [self.techDetailContent stopLoading];
//
//    [[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"WebKitCacheModelPreferenceKey"];
//    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitDiskImageCacheEnabled"];//自己添加的，原文没有提到。
//    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitOfflineWebApplicationCacheEnabled"];//自己添加的，原文没有提到。
//    [[NSUserDefaults standardUserDefaults] synchronize];
//    NSLog(@"11111");
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
